/**
 * 慢Sql查看界面
 */
define([
  './custom/widgets/js/yufpExcelExport.js'
], function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    yufp.lookup.reg('SCRIPT_CHANNEL_CODE,SCRIPT_CERT_TYPE,SCRIPT_SEX,SCRIPT_EDU_LEVEL,SCRIPT_LIVE_STATUS,SCRIPT_MARITAL_STATUS,SCRIPT_APP_STATUS');
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        return {
          searchFormdata: {},
          addApplyInfoDialog: false,
          queryApplyInfoUrl: backend.msScriptsApplyService + '/api/applyinfo/',
          height: 800,
          applyNo: '',
          startUrl: backend.msScriptsApplyService + '/api/applyhistory/asyncexport',
          // 异步时导出、导入结果查询
          progressUrl: backend.msScriptsApplyService + '/api/applyhistory/progress',
          // 下载
          downloadUrl: backend.msScriptsApplyService + '/api/applyhistory/download'
        };
      },
      computed: {
        action: function () {
          return yufp.service.getUrl({ url: this.uploadAction });
        }
      },
      mounted: function () {
        var _this = this;
        yufp.service.request({
          method: 'POST',
          url: backend.seqService + '/api/sequenceconfig/getSequenceTemplate/APPLY_SEQUENCE',
          dataType: 'string',
          callback: function (code, message, response) {
            if (code == 0) {
              _this.applyNo = response;
            }
          }
        });
      },
      methods: {
        //  查询按钮
        searchButton: function () {
          if (this.connectKey == undefined || this.connectKey.length == 0) {
            this.$message({ message: this.$t('monitorRedisIdempotent.pleaseChooseRedisConnectInfo'), type: 'warning' });
            return;
          }
          var requestUrl = backend.dashboardService + '/idempotent/failure/' + this.connectKey;
          if (this.chooseDate != undefined && this.chooseDate != '' && this.chooseDate.toJSON().length > 0) {
            requestUrl = requestUrl + '/' + this.chooseDate.toJSON();
          } else {
            this.$message({ message: this.$t('monitorRedisIdempotent.pleaseChooseQueryDate'), type: 'warning' });
            return;
          }
          var _this = this;
          yufp.service.request({
            method: 'GET',
            url: requestUrl,
            callback: function (code, message, response) {
              if (code == 0) {
                _this.redisIdempotentExceptionInfo = response.data;
              }
            }
          });
        },
        // 重置按钮
        resetFn: function () {
          this.connectKey = '';
          this.chooseDate = new Date();
        },
        // 新增申请
        addApplyInfo: function () {
          this.addApplyInfoDialog = true;
          var _this = this;
          this.$nextTick(function () {
            _this.$refs.addApplyInfoForm.resetFields();
          });
        },
        // 取消申请
        cancel: function () {
          this.addApplyInfoDialog = false;
        },
        // 发起申请
        startApply: function () {
          var _this = this;
          var validate = false;
          _this.$refs.addApplyInfoForm.validate(function (valid) {
            validate = valid;
          });
          if (!validate) {
            _this.$message({message: '请输入对应的信息', type: 'warning'});
            return;
          }
          var request = {};
          request.head = {};
          request.body = {};
          var dataform = _this.$refs.addApplyInfoForm.formdata;
          request.head.channelCode = dataform.channelCode;
          request.head.requestTime = yufp.util.dateFormat(new Date());
          request.head.transCode = 'APPLY01';
          request.head.transSeq = this.applyNo;
          yufp.extend(request.body, dataform);
          request.body.thirdNo = this.applyNo;
          _this.$confirm('是否确认发起提交申请', '确认申请', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(function () {
            yufp.service.request({
              method: 'POST',
              url: backend.msScriptsApplyService + '/api/apply/info/idempotent',
              data: JSON.stringify(request),
              callback: function (code, message, response) {
                if (code == 0) {
                  if (response.head.status == 'F') {
                    _this.$message({ message: '申请失败，原因：' + response.head.errorMsg, type: 'error' });
                  } else {
                    _this.$message('申请成功，申请编号为:' + response.body.applyNo);
                    _this.addApplyInfoDialog = false;
                    _this.$nextTick(function () {
                      _this.$refs.applyInfo.remoteData();
                    });
                  }
                } else {
                  _this.$message({ message: '申请失败', type: 'error' });
                }
              }
            });
          }).catch(function () {
            return;
          });
        },


        // 同步导出
        syncExportApplyInfo: function () {
          var url = yufp.settings.ssl ? 'https://' : 'http://';
          url += yufp.settings.url;
          url += backend.msScriptsApplyService;
          url += '/api/applyhistory/syncexport';
          window.open(yufp.util.addTokenInfo(url));
        }
      }

    });
  };

  // 消息处理
  exports.onmessage = function (type, message) {

  };

  // page销毁时触发destroy方法
  exports.destroy = function (id, cite) {

  };
});
